package com.zfast.yugioh.controller;

import com.github.pagehelper.PageInfo;
import com.zfast.forge.common.BaseResult;
import com.zfast.forge.common.Page;
import com.zfast.forge.valid.Create;
import com.zfast.yugioh.model.Card;
import com.zfast.yugioh.model.UserCard;
import com.zfast.yugioh.service.UserCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户卡集
 *
 * @author zgn
 * @email 
 * @date 2022-06-09 10:10:330
 */
@RestController
@RequestMapping("api/userCard")
@Api(tags = {"用户卡集Con"})
public class UserCardController{
    @Resource
    UserCardService userCardService;

    /*@PostMapping({"/list"})
    @ApiOperation(value = "用户卡集数据列表", httpMethod = "POST", notes = "获取用户卡集列表")
    public BaseResult<PageInfo<UserCard>> list(@RequestBody Page<UserCard> page) {
        BaseResult result=BaseResult.builder()
                .msg("获取用户卡集列表成功")
                .data(userCardService.pageList(page))
                .build();
        return result;
    }

    @PostMapping({"add"})
    @ApiOperation(value = "新增用户卡集信息", httpMethod = "POST", notes = "保存用户卡集")
    public BaseResult<Integer> add(@RequestBody @Validated(Create.class) UserCard model) {
        BaseResult result=BaseResult.builder()
                .msg("添加用户卡集成功")
                .data(userCardService.insert(model))
                .build();
        return result;
    }

    @PostMapping({"update"})
    @ApiOperation(value = "更新指定id的 用户卡集 信息（更新全部信息）", httpMethod = "POST", notes = "更新指定id的 用户卡集 信息（更新全部信息）")
    public BaseResult<Integer> update(@RequestBody @ApiParam(name = "userCard", value = "用户卡集业务对象", required = true) UserCard model) {
        BaseResult result=BaseResult.builder()
                .msg("更新用户卡集成功")
                .data(userCardService.update(model))
                .build();
        return result;
    }*/

    @PostMapping({"/listCardsByUserId"})
    @ApiOperation(value = "通过用户id获取卡牌信息", httpMethod = "POST", notes = "通过用户id获取卡牌信息")
    public BaseResult<List<Card>> listCardsByUserId(@RequestBody @ApiParam(name = "userId", value = "用户id", required = true) String userId) {
        BaseResult result=BaseResult.builder()
                .msg("获取用户卡集列表成功")
                .data(userCardService.findCardsByUserId(userId))
                .build();
        return result;
    }
}
